package paint;

import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.util.LinkedList;

/** This class set the width and height in pixels, cm, and inch.
 *   This function also converts the units from one form to another.
 *   There are two states which are disable and enable.
 *   The OS is windows.
 *   No there are no implementation variances.
 *   There are no security constraints.
 *   no external secification.
 *   @author Paint
 *   @version 2.0
 */
public class attributes extends javax.swing.JDialog {

    /** javax.swing.JDialog
     */
    /** INCH
     */
    /**takes in an INT from the screen resolution.
     */
    public static final int INCH = Toolkit.getDefaultToolkit().getScreenResolution();
    /** javax.swing.JDialog
     */
    /** im
     */
    /** is a bufferedImage variable.
     */
    public BufferedImage im;

    /*
     *If inches: lastSelected = 1
     *If cm: lastSelected = 2
     *If pixels: lastSelected = 3
     */
    /** javax.swing.JDialog
     */
    /** lastedSelected
     */
    /** any int number can be use.
     */
    public int lastSelected = 3;
    /** javax.swing.JDialog
     */
    /** w
     */
    /** takes in any string variable.
     */
    public String w = new String();
    /** javax.swing.JDialog
     */
    /** h
     */
    /** takes in any string variable.
     */
    public String h = new String();
    /** javax.swing.JDialog
     */
    /** Assigns the width of the pixel.
     */
    public double pixelWidth;
    /** Assigns the height of the pixel.
     */
    public double pixelHeight;
    /** Assigns the width of the inch.
     */
    public double inchWidth;
    /** Assigns the height of the inch.
     */
    public double inchHeight;
    /** Assigns the width of the cm.
     */
    public double cmWidth;
    /** Assigns the height of the cm.
     */
    public double cmHeight;
    /** The dialog is closed by OK.
     */
    public boolean ok_action;

    /** Convert pixels to inch and cm.
     * Paremeter can be either true or false.  Set modal to true.
     * NO return values.
     * No NULL values.
     * OS is windows.
     * No implementation variances.
     * exception of boolean value is given anything other than boolean values.
     * @param modal is a boolean
     * @param parent is a java.awt.Frame variable
     */
    public attributes(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        im = ((Paint) this.getParent()).center.getBufferedImage();

        /** converting to inches and cm*/
        pixelWidth = im.getWidth();
        pixelHeight = im.getHeight();
        cmWidth = Math.round((pixelWidth / ((double) INCH * (double) 2.54)) * 100) / 100.0;
        cmHeight = Math.round((pixelHeight / ((double) INCH * (double) 2.54)) * 100) / 100.0;
        inchWidth = Math.round((pixelWidth / (double) INCH) * 100) / 100.0;
        inchHeight = Math.round((pixelHeight / (double) INCH) * 100) / 100.0;

        w = w.valueOf(pixelWidth);
        h = h.valueOf(pixelHeight);

        widthText.setText(w);
        heightText.setText(h);

        if (((Paint) this.getParent()).grayscaleFlag == 0) {
            colorScale.setSelected(true);
        } else {
            blackwhite.setSelected(true);
        }

        ok_action = true;
    /*FAULT:: ok_action = false; */
    }

    /*public String getInches(){
    return inches.getText();
    }
    
    public String getCancel(){
    return cancel.getText();
    }
    
    public String getCm(){
    return cm.getText();
    }
    public String getMyWidth(){
    return Width.getText();
    }
    public String getMyHeight(){
    return Height.getText();
    }
    public void setLastSelected(int i){
    lastSelected=i;
    }
     */
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     * There is no state of transition.
     * There are no arguments.
     * No NULL values.
     * No return values.
     * Basically initializing.
     * OS is windows.
     * No implementation variances.
     * No exceptions.
     * NO security constraints.
     */
    public void initComponents() {

        /** javax.swing.ButtonGroup
         */
        /** unitsButtons
         */
        /** This is a ButtonGroup variable.
         */
        unitsButtons = new javax.swing.ButtonGroup();

        /** javax.swing.ButtonGroup
         */
        /** colors
         */
        /** This is a ButtonGroup variable.
         */
        colors = new javax.swing.ButtonGroup();

        /** javax.swing.JPanel
         */
        /** okCancel
         */
        /** This is a JPanel variable.
         */
        okCancel = new javax.swing.JPanel();

        /** javax.swing.ButtonGroup
         */
        /** ok
         */
        /** This is a JButton variable.
         */
        ok = new javax.swing.JButton();

        /** javax.swing.JButton
         */
        /** cancel
         */
        /** This is a JButton variable.
         */
        cancel = new javax.swing.JButton();

        /** javax.swing.JPanel
         */
        /** buttonsText
         */
        /** This is a JPanel variable.
         */
        buttonsText = new javax.swing.JPanel();

        /** javax.swing.JPanel
         */
        /** units
         */
        /** This is a JPanel variable.
         */
        units = new javax.swing.JPanel();

        /** javax.swing.JRadioButton
         */
        /** inches
         */
        /** This is a JRadioButton variable.
         */
        inches = new javax.swing.JRadioButton();

        /** javax.swing.JRadioButton
         */
        /** cm
         */
        /** This is a JRadioButton variable.
         */
        cm = new javax.swing.JRadioButton();

        /** javax.swing.JRadioButton
         */
        /** pixels
         */
        /** This is a JRadioButton variable.
         */
        pixels = new javax.swing.JRadioButton();

        /** javax.swing.JPanel
         */
        /** widthHeight
         */
        /** This is a JPanel variable.
         */
        widthHeight = new javax.swing.JPanel();

        /** javax.swing.JTextField
         */
        /** widthText
         */
        /** This is a JTextField variable.
         */
        widthText = new javax.swing.JTextField();

        /** javax.swing.JTextField
         */
        /** heightText
         */
        /** This is a JTextField variable
         */
        heightText = new javax.swing.JTextField();

        /** javax.swing.JLabel
         */
        /** Height
         */
        /** This is a JLabel variable
         */
        Height = new javax.swing.JLabel();

        /** javax.swing.JLabel
         */
        /** Width
         */
        /** This is a JLabel variable
         */
        Width = new javax.swing.JLabel();

        /** javax.swing.JLabel
         */
        /** color
         */
        /** This is a JLabel variable
         */
        color = new javax.swing.JPanel();

        /** javax.swing.JRadioButton
         */
        /** colorScale
         */
        /** This is a JRadioButton variable
         */
        colorScale = new javax.swing.JRadioButton();

        /** javax.swing.JRadioButton
         */
        /** blackwhite
         */
        /** This is a JRadioButton variable
         */
        blackwhite = new javax.swing.JRadioButton();

        addWindowListener(new java.awt.event.WindowAdapter() {

            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        okCancel.setLayout(new java.awt.GridBagLayout());
        java.awt.GridBagConstraints gridBagConstraints1;

        ok.setText("OK");
        ok.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okActionPerformed(evt);
            }
        });

        gridBagConstraints1 = new java.awt.GridBagConstraints();
        okCancel.add(ok, gridBagConstraints1);

        cancel.setText("CANCEL");
        cancel.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelActionPerformed(evt);
            }
        });

        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 1;
        okCancel.add(cancel, gridBagConstraints1);

        getContentPane().add(okCancel, java.awt.BorderLayout.EAST);

        buttonsText.setLayout(new java.awt.GridBagLayout());
        java.awt.GridBagConstraints gridBagConstraints2;

        units.setLayout(new java.awt.GridBagLayout());
        java.awt.GridBagConstraints gridBagConstraints3;

        units.setBorder(new javax.swing.border.TitledBorder("Units"));
        inches.setText("Inches");
        unitsButtons.add(inches);
        inches.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inchesActionPerformed(evt);
            }
        });

        gridBagConstraints3 = new java.awt.GridBagConstraints();
        gridBagConstraints3.insets = new java.awt.Insets(0, 0, 0, 10);
        units.add(inches, gridBagConstraints3);

        cm.setText("Cm");
        unitsButtons.add(cm);
        cm.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmActionPerformed(evt);
            }
        });

        gridBagConstraints3 = new java.awt.GridBagConstraints();
        gridBagConstraints3.insets = new java.awt.Insets(0, 10, 0, 10);
        units.add(cm, gridBagConstraints3);

        pixels.setSelected(true);
        pixels.setText("Pixels");
        unitsButtons.add(pixels);
        pixels.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pixelsActionPerformed(evt);
            }
        });

        gridBagConstraints3 = new java.awt.GridBagConstraints();
        gridBagConstraints3.insets = new java.awt.Insets(0, 10, 0, 0);
        units.add(pixels, gridBagConstraints3);

        gridBagConstraints2 = new java.awt.GridBagConstraints();
        gridBagConstraints2.gridx = 0;
        gridBagConstraints2.gridy = 1;
        gridBagConstraints2.insets = new java.awt.Insets(20, 0, 0, 0);
        gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
        buttonsText.add(units, gridBagConstraints2);

        widthHeight.setLayout(new java.awt.GridBagLayout());
        java.awt.GridBagConstraints gridBagConstraints4;

        widthText.setColumns(5);
        widthText.setMaximumSize(new java.awt.Dimension(4, 20));
        gridBagConstraints4 = new java.awt.GridBagConstraints();
        gridBagConstraints4.gridx = 1;
        gridBagConstraints4.gridy = 0;
        widthHeight.add(widthText, gridBagConstraints4);

        heightText.setColumns(5);
        heightText.setMaximumSize(new java.awt.Dimension(4, 20));
        gridBagConstraints4 = new java.awt.GridBagConstraints();
        gridBagConstraints4.gridx = 4;
        gridBagConstraints4.gridy = 0;
        widthHeight.add(heightText, gridBagConstraints4);

        Height.setText("Height");
        gridBagConstraints4 = new java.awt.GridBagConstraints();
        gridBagConstraints4.gridx = 3;
        gridBagConstraints4.gridy = 0;
        gridBagConstraints4.insets = new java.awt.Insets(0, 30, 0, 0);
        widthHeight.add(Height, gridBagConstraints4);

        Width.setText("Width");
        gridBagConstraints4 = new java.awt.GridBagConstraints();
        gridBagConstraints4.gridx = 0;
        gridBagConstraints4.gridy = 0;
        widthHeight.add(Width, gridBagConstraints4);

        gridBagConstraints2 = new java.awt.GridBagConstraints();
        gridBagConstraints2.gridx = 0;
        gridBagConstraints2.gridy = 0;
        gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
        buttonsText.add(widthHeight, gridBagConstraints2);

        color.setLayout(new java.awt.GridBagLayout());
        java.awt.GridBagConstraints gridBagConstraints5;

        color.setBorder(new javax.swing.border.TitledBorder(
                new javax.swing.border.EtchedBorder(), "Color"));
        colorScale.setText("color");
        colors.add(colorScale);
        gridBagConstraints5 = new java.awt.GridBagConstraints();
        gridBagConstraints5.insets = new java.awt.Insets(0, 0, 0, 10);
        color.add(colorScale, gridBagConstraints5);

        blackwhite.setText("black and white");
        colors.add(blackwhite);
        gridBagConstraints5 = new java.awt.GridBagConstraints();
        gridBagConstraints5.insets = new java.awt.Insets(0, 10, 0, 0);
        color.add(blackwhite, gridBagConstraints5);

        gridBagConstraints2 = new java.awt.GridBagConstraints();
        gridBagConstraints2.gridx = 0;
        gridBagConstraints2.gridy = 2;
        gridBagConstraints2.insets = new java.awt.Insets(20, 0, 0, 0);
        gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
        buttonsText.add(color, gridBagConstraints2);

        getContentPane().add(buttonsText, java.awt.BorderLayout.WEST);
        /*FAULT:: inches.setText("poop");*/
        pack();
    }

    /** This method performs the action by the user.
     * There is no state of transition.
     * The argument is an ActionEvent variable.
     * No NULL values.
     * No return values.
     * Basically initializing.
     * OS is windows.
     * No implementation variances.
     * No exceptions.
     * NO security constraints.
     * @param evt ActionEvent
     */
    public void okActionPerformed(java.awt.event.ActionEvent evt) {
        // Add your handling code here:
        //If the Width and Height aren't the same as they started out, then
        //you need to crop the image.

        /** javax.swing.JRadioButton
         */
        /** currWidth
         */
        /** This is a double variable
         */
        double currWidth = Double.parseDouble(widthText.getText());

        /** javax.swing.JRadioButton
         */
        /** currHeight
         */
        /** This is a double variable
         */
        double currHeight = Double.parseDouble(heightText.getText());

        /** javax.swing.JRadioButton
         */
        /** x1
         */
        /** This is a double variable
         */
        double x1 = im.getMinX();

        /** javax.swing.JRadioButton
         */
        /** y1
         */
        /** This is a double variable
         */
        double y1 = im.getMinY();

        // ming 4.22
        if (currWidth * currHeight >= 3000000) {
            ok_action = false;

        } else {
            ok_action = true;
            BufferedImage im = ((Paint) this.getParent()).center.getBufferedImage();
            int old_width = im.getWidth();
            int old_height = im.getHeight();

            double newPixW = currWidth;
            double newPixH = currHeight;
            // ming 4.22 end

            if (lastSelected == 1) {

                // ming 4.22
                newPixW = currWidth * 72;
                newPixH = currHeight * 72;
            //    if (old_width!=(int)(newPixW+0.5) || old_height!=(int)(newPixH+0.5))
            // ming 4.22 end
            //	  ((Paint)this.getParent()).center.resizeImage((int)newPixW, (int)newPixH);
            }
            if (lastSelected == 2) {
                //cm
                //double newPixW = Math.round((currWidth * (double)INCH) * (double)2.54 * 100)/100.0;
                //double newPixH = Math.round((currHeight * (double)INCH) * (double)2.54 * 100)/100.0;
                // ming 4.22
                newPixW = currWidth * 72 / 2.54;
                newPixH = currHeight * 72 / 2.54;
            //   if (old_width!=(int)(newPixW+0.5) || old_height!=(int)(newPixH+0.5))
            // ming 4.22 end
            //  ((Paint)this.getParent()).center.resizeImage((int)newPixW, (int)newPixH);
            }
            if (lastSelected == 3) {
                //pixels
                // ming 4.22
                //  if (old_width!=(int)(newPixW+0.5) || old_height!=(int)(newPixH+0.5))
                // ming 4.22 end
                //  ((Paint)this.getParent()).center.resizeImage((int)currWidth, (int)currHeight);
            }

            // ming 4.22
            if (old_width != (int) (newPixW + 0.5) || old_height != (int) (newPixH + 0.5)) {
                // ming 4.24
                //	      ((Paint)this.getParent()).center.setBufferedImage(im);
                // ming 4.24 end
                // ming 4.26
                int cur_layer = ((Paint) this.getParent()).center.currentLayer;
                LinkedList cur_action_list = (LinkedList) (((Paint) this.getParent()).action_list.get(cur_layer));
                LinkedList cur_redo_list = (LinkedList) (((Paint) this.getParent()).redo_list.get(cur_layer));

                int temp1 = cur_redo_list.size();
                for (int i = 0; i < temp1; i++) {
                    cur_redo_list.removeLast();
                }
                cur_action_list.add("Change size");

                // ming 4.26 end
                ((Paint) this.getParent()).updateUndoList();

                if (lastSelected == 1) {
                    ((Paint) this.getParent()).center.resizeImage(
                            (int) newPixW, (int) newPixH);
                } else if (lastSelected == 2) {
                    ((Paint) this.getParent()).center.resizeImage(
                            (int) newPixW, (int) newPixH);
                } else if (lastSelected == 3) {
                    ((Paint) this.getParent()).center.resizeImage(
                            (int) currWidth, (int) currHeight);
                }
                ((Paint) this.getParent()).center.setZoom(((Paint) this.getParent()).center.getZoom());
            }
            // ming 4.22 end

            // ming 4.22
            //	  if (old_width!=(int)(newPixW+0.5) || old_height!=(int)(newPixH+0.5))
			/*	  {
            ((Paint)this.getParent()).center.setBufferedImage(im);
            int temp1 = ((Paint)this.getParent()).redo_list.size();
            for (int i=0; i<temp1; i++)
            ((Paint)this.getParent()).redo_list.removeLast();
            ((Paint)this.getParent()).action_list.add("Change size");
            ((Paint)this.getParent()).updateUndoList();
            }*/
            // ming 4.22 end
            im = ((Paint) this.getParent()).center.getBufferedImage();
            // ming 4.22
            boolean cur_grayscale = ((Paint) this.getParent()).center.getGrayscale();

            //check to see if they want to change to black&white or color
            if (!cur_grayscale && blackwhite.isSelected()) {
                // ming 4.22 end
                // ming 4.4
                //    if ( ((Paint)this.getParent()).grayscaleFlag == 0 ){
                // ming 4.4 end
                BufferedImage gray = new BufferedImage(im.getWidth(), im.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
                Graphics2D g = gray.createGraphics();

                g.drawImage(im, im.getMinX(), im.getMinY(), im.getWidth(), im.getHeight(), null);
                ((Paint) this.getParent()).center.setBufferedImage(gray);

                ((Paint) this.getParent()).changeToGray(true);

                // ming 4.22
                // ming 4.26
                int cur_layer = ((Paint) this.getParent()).center.currentLayer;
                LinkedList cur_action_list = (LinkedList) (((Paint) this.getParent()).action_list.get(cur_layer));
                LinkedList cur_redo_list = (LinkedList) (((Paint) this.getParent()).redo_list.get(cur_layer));

                int temp1 = cur_redo_list.size();
                for (int i = 0; i < temp1; i++) {
                    cur_redo_list.removeLast();
                }
                cur_action_list.add("Change to gray scale");

                // ming 4.26 end
                ((Paint) this.getParent()).updateUndoList();
                gray.flush();
            // ming 4.22 end
            // ming 4.4
            //((Paint)this.getParent()).grayscaleFlag = 1;
            //}
            // ming 4.4 end
            }
            // ming 4.22
			/*	  if (colorScale.isSelected()){
            // ming 4.4
            //if ( ((Paint)this.getParent()).grayscaleFlag == 1 ){
            // ming 4.4 end
            
            BufferedImage cImg = new BufferedImage(im.getWidth(),im.getHeight(),BufferedImage.TYPE_INT_RGB);
            Graphics2D g = cImg.createGraphics();
            
            g.drawImage(im,im.getMinX(),im.getMinY(),im.getWidth(),im.getHeight(),null);
            ((Paint)this.getParent()).center.setBufferedImage(cImg);
            
            ((Paint)this.getParent()).changeToGray( false );
            
            // ming 4.4
            //((Paint)this.getParent()).grayscaleFlag = 0;
            //}
            // ming 4.4 end
            }*/
            im.flush();
        }
        // ming 4.22 end
        ((Paint) this.getParent()).center.repaint();
        im.flush();

        //Close the window when you're done
        setVisible(false);
        dispose();
    // ming 4.22
    //	  ok_action = true;
    // ming 4.22 end
    }

    /** This method controls the pixels performed by the user.
     * There is no state of transition.
     * The argument is an ActionEvent variable.
     * No NULL values.
     * No return values.
     * Basically initializing.
     * OS is windows.
     * No implementation variances.
     * No exceptions.
     * NO security constraints.
     * @param evt ActionEvent
     */
    public void pixelsActionPerformed(java.awt.event.ActionEvent evt) {
        // Add your handling code here:
        //change widthText from cm or inches to pixels

        if (lastSelected == 1) {

            inchWidth = Double.parseDouble(widthText.getText());
            inchHeight = Double.parseDouble(heightText.getText());

            inchWidth = Math.round((inchWidth * 72) * 100 / 100.0);
            inchHeight = Math.round((inchHeight * 72) * 100 / 100.0);

            w = w.valueOf(inchWidth);
            h = h.valueOf(inchHeight);

            //	  w = w.valueOf( Math.round( ( inchWidth /(double)INCH ) * 100)/100.0
            //);
            //	  h = h.valueOf( Math.round( ( inchHeight /(double)INCH) * 100)/100.0
            //);
			/*FAULT::w = String.valueOf(pixelWidth);*/
            widthText.setText(w);
            heightText.setText(h);
        }
        if (lastSelected == 2) {
            cmWidth = Double.parseDouble(widthText.getText());
            cmHeight = Double.parseDouble(heightText.getText());

            cmWidth = Math.round(((cmWidth * 72) * 100 / 2.54) / 100.0);
            cmHeight = Math.round(((cmHeight * 72) * 100 / 2.54) / 100.0);

            w = w.valueOf(cmWidth);
            h = h.valueOf(cmHeight);

            //
            //w = w.valueOf(
            //				Math.round(( cmWidth /((double)INCH *
            //							(double)2.54))*100)/100.0 );
            //h = h.valueOf(
            //				Math.round(( cmHeight /((double)INCH *
            //							(double)2.54))*100)/100.0 );

            widthText.setText(w);
            heightText.setText(h);

        }

        lastSelected = 3;
    }

    /** This method performs the action by the user.
     * There is no state of transition.
     * The argument is an ActionEvent variable.
     * No NULL values.
     * No return values.
     * Basically initializing.
     * OS is windows.
     * No implementation variances.
     * No exceptions.
     * NO security constraints.
     * @param evt ActionEvent
     */
    public void cmActionPerformed(java.awt.event.ActionEvent evt) {
        // Add your handling code here:
        //change widthText from pixels or inches to centimeters
        if (lastSelected == 1) {
            //converting from inches
            inchWidth = Double.parseDouble(widthText.getText());
            inchHeight = Double.parseDouble(heightText.getText());

            /** javax.swing.JRadioButton
             */
            /** width
             */
            /** This is a double variable
             */
            double width = Double.parseDouble(widthText.getText());

            /** javax.swing.JRadioButton
             */
            /** height
             */
            /** This is a double variable
             */
            double height = Double.parseDouble(heightText.getText());

            width = width * (double) 2.54;
            height = height * (double) 2.54;

            width = Math.round(width * 100) / 100.0;
            height = Math.round(height * 100) / 100.0;

            w = w.valueOf(width);
            h = h.valueOf(height);

            //after we've calculated the values, we finally set the text
			/*FAULT::w=String.valueOf(cmWidth);*/
            widthText.setText(w);
            heightText.setText(h);
        }
        if (lastSelected == 3) {
            //converting from pixels
            pixelHeight = Double.parseDouble(heightText.getText());
            pixelWidth = Double.parseDouble(widthText.getText());

            pixelWidth = Math.round(((double) pixelWidth) * 2.54 / (72) * 100) / 100.0;
            pixelHeight = Math.round(((double) pixelHeight) * 2.54 / (72) * 100) / 100.0;

            w = w.valueOf(pixelWidth);
            h = h.valueOf(pixelHeight);

            //	      w = w.valueOf(cmWidth);
            //	      h = h.valueOf(cmHeight);

            //after we've calculated the values, we finally set the text

            widthText.setText(w);
            heightText.setText(h);
        }

        lastSelected = 2;
    }

    /** This method performs the action by the user.
     * There is no state of transition.
     * The argument is an ActionEvent variable.
     * No NULL values.
     * No return values.
     * Basically initializing.
     * OS is windows.
     * No implementation variances.
     * No exceptions.
     * NO security constraints.
     * @param evt ActionEvent
     */
    public void inchesActionPerformed(java.awt.event.ActionEvent evt) {
        // Add your handling code here:
        //change widthText from pixels or centimeters to inches
        if (lastSelected == 2) {
            //converting from cm

            cmWidth = Double.parseDouble(widthText.getText());
            cmHeight = Double.parseDouble(heightText.getText());

            /** javax.swing.JRadioButton
             */
            /** width
             */
            /** This is a double variable
             */
            double width = Double.parseDouble(widthText.getText());

            /** javax.swing.JRadioButton
             */
            /** height
             */
            /** This is a double variable
             */
            double height = Double.parseDouble(heightText.getText());

            width = width / (double) 2.54;
            height = height / (double) 2.54;

            width = Math.round(width * 100) / 100.0;
            height = Math.round(height * 100) / 100.0;

            w = w.valueOf(width);
            h = h.valueOf(height);

            //after we've calculated the values, we finally set the text
			/*FAULT::w = String.valueOf(inchWidth);*/
            widthText.setText(w);
            heightText.setText(h);
        }
        if (lastSelected == 3) {

            pixelHeight = Double.parseDouble(heightText.getText());
            pixelWidth = Double.parseDouble(widthText.getText());

            pixelWidth = Math.round((pixelWidth / 72) * 100) / 100.0;
            pixelHeight = Math.round((pixelHeight / 72) * 100) / 100.0;

            w = w.valueOf(pixelWidth);
            h = h.valueOf(pixelHeight);

            //after we've calculated the values, we finally set the text
            widthText.setText(w);
            heightText.setText(h);
        }

        lastSelected = 1;
    }

    /** This method performs the action by the user.
     * There is no state of transition.
     * The argument is an ActionEvent variable.
     * No NULL values.
     * No return values.
     * Basically initializing.
     * OS is windows.
     * No implementation variances.
     * No exceptions.
     * NO security constraints.
     * @param evt ActionEvent
     */
    public void cancelActionPerformed(java.awt.event.ActionEvent evt) {
        // Add your handling code here:
        setVisible(false);
        dispose();
    /*FAULT::setVisible(true);*/
    }

    /** This method performs the action by the user.
     * There is no state of transition.
     * The argument is an ActionEvent variable.
     * No NULL values.
     * No return values.
     * Basically initializing.
     * OS is windows.
     * No implementation variances.
     * No exceptions.
     * NO security constraints.
     * @param evt WindowEvent
     */
    public void closeDialog(java.awt.event.WindowEvent evt) {
        setVisible(false);
        dispose();
    /*FAULT::setVisible(true);*/
    }

    /** This is the method which creates a new attribute
     * Set the args variable with strings.
     * Variable can be set to NULL.
     * No return value.
     * No algorithm defined.
     * OS is windows.
     * No implementation variances
     * exception would be thrown if there is a number assign to the parameter.
     * No security constraints.
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new attributes(new javax.swing.JFrame(), true).show();
    }

    // Variables declaration - do not modify
    /** javax.swing.ButtonGroup
     */
    /** unitsButtons
     */
    /** This is a ButtonGroup variable.
     */
    private javax.swing.ButtonGroup unitsButtons;
    /** javax.swing.ButtonGroup
     */
    /** colors
     */
    /** This is a ButtonGroup variable.
     */
    private javax.swing.ButtonGroup colors;
    /** javax.swing.JRadioButton
     */
    /** colorScale
     */
    /** This is a JRadioButton variable.
     */
    private javax.swing.JPanel okCancel;
    /** javax.swing.ButtonGroup
     */
    /** ok
     */
    /** This is a JButton variable.
     */
    private javax.swing.JButton ok;
    /** javax.swing.JButton
     */
    /** cancel
     */
    /** This is a JButton variable.
     */
    public javax.swing.JButton cancel;
    /** javax.swing.JPanel
     */
    /** buttonsText
     */
    /** This is a JPanel variable.
     */
    private javax.swing.JPanel buttonsText;
    /** javax.swing.JPanel
     */
    /** units
     */
    /** This is a JPanel variable.
     */
    private javax.swing.JPanel units;
    /** javax.swing.JRadioButton
     */
    /** inches
     */
    /** This is a JRadioButton variable.
     */
    public javax.swing.JRadioButton inches;
    /** javax.swing.JRadioButton
     */
    /** cm
     */
    /** This is a JRadioButton variable.
     */
    public javax.swing.JRadioButton cm;
    /** javax.swing.JRadioButton
     */
    /** pixels
     */
    /** This is a JRadioButton variable.
     */
    private javax.swing.JRadioButton pixels;
    /** javax.swing.JPanel
     */
    /** widthHeight
     */
    /** This is a JPanel variable.
     */
    private javax.swing.JPanel widthHeight;
    /** javax.swing.JTextField
     */
    /** widthText
     */
    /** This is a JTextField variable.
     */
    private javax.swing.JTextField widthText;
    /** javax.swing.JTextField
     */
    /** heightText
     */
    /** This is a JTextField variable.
     */
    private javax.swing.JTextField heightText;
    /** javax.swing.JLabel
     */
    /** Height
     */
    /** This is a JLabel variable.
     */
    public javax.swing.JLabel Height;
    /** javax.swing.JLabel
     */
    /** Width
     */
    /** This is a JLabel variable.
     */
    public javax.swing.JLabel Width;
    /** javax.swing.JLabel
     */
    /** color
     */
    /** This is a JLabel variable.
     */
    private javax.swing.JPanel color;
    /** javax.swing.JRadioButton
     */
    /** colorScale
     */
    /** This is a JRadioButton variable.
     */
    private javax.swing.JRadioButton colorScale;
    /** javax.swing.JRadioButton
     */
    /** blackwhite
     */
    /** This is a JRadioButton variable.
     */
    private javax.swing.JRadioButton blackwhite;

    // End of variables declaration
}